package leecode.二叉树;

/**
 * @author wangxi03 created on 2021/6/24 4:42 下午
 * @version v1.0
 *
 * https://www.nowcoder.com/questionTerminal/185a87cd29eb42049132aed873273e83
 */
public class SumNumbers {
    int res = 0;
    public int sumNumbers (TreeNode root) {
        // write code here
        if (root == null) {
            return 0;
        }
        help(root, "");
        return res;
    }

    private void help(TreeNode root, String s) {
        if (root == null) {
            return ;
        }
        if (root.left == null && root.right == null) {
            res += Integer.parseInt(s + root.val);
            return;
        }
        help(root.left, s + root.val);
        help(root.right, s + root.val);
    }
}
